<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="root"></div>
    <!-- 添加依赖 -->
    <script src="https://unpkg.com/react@18/umd/react.development.js" crossorigin></script>
    <script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js" crossorigin></script>
    <!-- babel -->
    <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
    <!-- react代码 -->
    <script type="text/babel">
        const root = ReactDOM.createRoot(document.querySelector("#root"))
        let message= "hello world"
        function btnClick(){
            console.log("btnClick");
            // 1.修改数据
            message = "hello react"
            // 2.重新渲染界面
            rootRender()
        }
        // root.render(
        //     <div>
        //     <h2>{message}</h2> 
        //     <button onClick={btnClick}>修改</button>  
        //     </div>
        // )

        // 3.封装一个渲染函数
            function rootRender(){
                root.render(
                    <div>
                        <h2>{message}</h2> 
                        <button onClick={btnClick}>修改</button>  
                    </div>
                )
            }
            rootRender()

    </script>
</body> 
</html>